package com.wang.service.impl;

import com.wang.dto.PayInfoDto;
import com.wang.entity.PayInfo;
import com.wang.entity.User;
import com.wang.mapper.PayInfoMapper;
import com.wang.mapper.UserMapper;
import com.wang.service.PayInfoService;
import com.wang.utils.ResponseEnum;
import com.wang.utils.ResponseUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Classname PayInfoServiceImpl
 * @Description TODO
 * @Date 2024/9/19 13:48
 * @Created by pc
 */
@Service
@Transactional
public class PayInfoServiceImpl implements PayInfoService {
    @Resource
    private PayInfoMapper payInfoMapper;

    @Resource
    private UserMapper userMapper;
    @Override
    public ResponseUtil findAll() {
        List<PayInfo> payInfoList = payInfoMapper.findAll();
        List<PayInfoDto> list = new ArrayList<>();
        payInfoList.forEach(payInfo -> {
            Integer userId = payInfo.getUserId();
            User user = userMapper.findByUserId(userId);
            PayInfoDto payInfoDto = new PayInfoDto();
            BeanUtils.copyProperties(payInfo,payInfoDto);
            user.setPassword(null);
            user.setSalt(null);
            payInfoDto.setUser(user);
            list.add(payInfoDto);
        });
        return ResponseUtil.get(ResponseEnum.PAY_INFO_FINDALL_SUCCESS,list);
    }
}
